<template>
  <div id="root">
    <h1>vue使用代理服务器解决跨域问题</h1>
    <button @click="queryStudents">点击获取students数据</button>
    <button @click="queryCars">点击获取cars数据</button>
   </div>
</template>

<script>
import axios from 'axios'
export default {
   name:"App",
   components:{},
   methods:{
      //学习地址：https://cli.vuejs.org/zh/config/#devserver-proxy
      queryStudents(){
         axios.get("http//localhost:8080/atguigu/students").then(
            response => {
               console.log("请求成功,获取到students数据为:",response.data);
               
            },
            error => {
               console.log("请求失败，失败原因:",error.message);
            }
         )
      },
      queryCars(){
         axios.get("http//localhost:8080/api/cars").then(
            response => {
               console.log("请求成功,获取到cars数据为:",response.data);
               
            },
            error => {
               console.log("请求失败，失败原因:",error.message);
            }
         )
      }
   }
}
</script>

<style>

</style>

